//**************************************************************************************
/** \file virdemo_classes.cpp
 *    This file contains some classes which don't do much of anything except for 
 *    causing virtual and non-virtual methods to be called.  The idea is to see how
 *    long, on average, it takes to get such methods to run.  
 *
 *  Revisions:
 *    \li 02-03-2008 JRR Original file
 *    \li 03-04-2008 JRR Added multiple inheritance tests
 *    \li 05-06-2008 JRR Changed to use new serial port classes
 *    \li 01-29-2009 JRR Changed again to use even newer serial port classes
 *    \li 04-19-2012 JRR Stripped out speed test stuff to make clearer demonstration
 *
 *  License:
 *    This file copyright 2007-2012 by JR Ridgely. It is released under the Lesser GNU
 *    public license, version 2.
 */
//**************************************************************************************

#include <avr/io.h>
#include "rs232int.h"
#include "global_debug.h"
#include "virdemo_classes.h"


/** This define is defined if we want the methods to print out who they are so we can
 *  see which method is run by which call. 
 */
#define PRINT_WHO_RUNS


//--------------------------------------------------------------------------------------
/** This constructor creates an object of the parent class. It will also be called when
 *  a child class object is being created. 
 *  @param p_serial A pointer to the serial port used to display messages
 */

mom_class::mom_class (base_text_serial* p_serport)
{
	ser_port = p_serport;

	*ser_port << "Constructor: Mom class" << endl;
}


//--------------------------------------------------------------------------------------
/** This is an ordinary method belonging to the parent class; it will be overridden in
 *  the child class. 
 */

void mom_class::omethod (void)
{
	# ifdef PRINT_WHO_RUNS
		*ser_port << "Ordinary method: Mom class" << endl;
	#endif
}


//--------------------------------------------------------------------------------------
/** This method is declared virtual, so when a pointer to the child class is used, the
 *  runtime system will have to figure out if the parent class's method or the child
 *  class's method is actually going to be called. 
 */

void mom_class::vmethod (void)
{
	# ifdef PRINT_WHO_RUNS
		*ser_port << "Virtual method: Parent class" << endl;
	#endif
}
		
		
//--------------------------------------------------------------------------------------
/** This constructor passes a pointer to the serial port to the parent class's
 *  constructor. 
 *  @param p_serial A pointer to the serial port used to display messages
 */

child_class::child_class (base_text_serial* p_serial)
	: mom_class (p_serial)
{
	*ser_port << "Constructor: Child class" << endl;
}


//--------------------------------------------------------------------------------------
/** This method overrides the parent class's ordinary method. Running it should not 
 *  require the use of virtual method tables, and it should run faster than a virtual
 *  method does. 
 */

void child_class::omethod (void)
{
	# ifdef PRINT_WHO_RUNS
		*ser_port << "Ordinary method: Child class" << endl;
	#endif
}


//--------------------------------------------------------------------------------------
/** This method is declared virtual in the parent class, and when it is called, the 
 *  runtime system will have to figure out whether this method or the parent class's
 *  method is actually supposed to run. 
 */

void child_class::vmethod (void)
{
	# ifdef PRINT_WHO_RUNS
		*ser_port << "Virtual method: Child class" << endl;
	#endif
}


//--------------------------------------------------------------------------------------
/** This is an ordinary function which is called without using the C++ class structure
 *  at all. 
 */

void just_function (void)
{
	# ifdef PRINT_WHO_RUNS
		GLOB_DEBUG ("Ordinary C function" << endl);			// See lib/global_debug.h
	#endif
}
